<?php

/**
 * This is the model class for table "pjm_order".
 *
 * The followings are the available columns in table 'pjm_order':
 * @property integer $orderId
 * @property string $customerName
 * @property string $customerEmail
 * @property string $customerAddress
 * @property string $customerPhone
 * @property string $customerCity
 * @property string $customerCountry
 * @property string $createDate
 */
class Order extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Order the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pjm_order';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('customerName, customerEmail, customerAddress, customerPhone, customerCity, customerCountry', 'required'),
			array('orderId', 'numerical', 'integerOnly'=>true),
			array('customerName, customerEmail', 'length', 'max'=>50),
			array('customerAddress', 'length', 'max'=>255),
			array('customerPhone, customerCountry', 'length', 'max'=>30),
			array('customerCity', 'length', 'max'=>20),
			array('createDate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('orderId, customerName, customerEmail, customerAddress, customerPhone, customerCity, customerCountry, createDate', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'orderId' => 'Order',
			'customerName' => 'Customer Name',
			'customerEmail' => 'Customer Email',
			'customerAddress' => 'Customer Address',
			'customerPhone' => 'Customer Phone',
			'customerCity' => 'Customer City',
			'customerCountry' => 'Customer Country',
			'createDate' => 'Create Date',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('orderId',$this->orderId);
		$criteria->compare('customerName',$this->customerName,true);
		$criteria->compare('customerEmail',$this->customerEmail,true);
		$criteria->compare('customerAddress',$this->customerAddress,true);
		$criteria->compare('customerPhone',$this->customerPhone,true);
		$criteria->compare('customerCity',$this->customerCity,true);
		$criteria->compare('customerCountry',$this->customerCountry,true);
		$criteria->compare('createDate',$this->createDate,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}